import {ref, computed} from 'vue'
import {defineStore} from 'pinia'

export const userStore = defineStore('user', () => {
    const doubleCount = computed(() => count.value * 2)
    let loginUser = ref({})
    let powerName = ref(false);
    let powerNumber = ref(1);
    let root = ref(false);
    let master = ref(false);
    let admin = ref(false);
    let normal = ref(false);
    let user = ref(false);
    let authorization = ref("123123123123");

    function setLoginUser(userFromServer) {
        if (userFromServer) {
            loginUser.value = userFromServer;
            powerName.value = userFromServer.powerName;
            powerNumber.value = userFromServer.powerNumber;
            const power = loginUser.value.powerNumber;
            user.value = true
            if (power >= 99) {
                normal.value = true;
            }
            if (power >= 99999) {
                admin.value = true;
            }
            if (power >= 9999999) {
                master.value = true;
            }
            if (power >= 999999999) {
                root.value = true;
            }
            loginUser.value.powerName = null;
            loginUser.value.powerNumber = null;
        }
    }

    function delLoginUser() {
        loginUser = ref({})
        powerName = ref(false);
        powerNumber = ref(1);
        root = ref(false);
        master = ref(false);
        admin = ref(false);
        normal = ref(false);
        user = ref(false);
        authorization = ref("");
    }

    return {loginUser, setLoginUser, root, master, admin, normal, user, authorization, powerNumber}
})
